
//useReducer的使用过程

//1.要创建reducer,reducer其实就是一个纯函数,接收state和action作为参数

//2.state是一个状态,action是一个对象,这个对象中一定要添加一个叫做type的属性

//3.将reducer传入到useRed

//4.通过dispath传递action来修改状态

import reducer from "./store/reducers"
import { useReducer } from "react"

let UseReducerCom = () => {

    //使用useReducer
    let [state, dispatch] = useReducer(reducer, 44)

    //增加
    let increase = () => {
        let action = {
            type: "ADD",
            payload: 5
        }
        //@ts-ignore
        dispatch(action)
    }

    //减少
    let decrease = () => {

    }
    return (
        <fieldset>
            <legend>useReducer</legend>
            <button>-</button>
            &nbsp;
            &nbsp;
            <b>{state}</b>
            &nbsp;
            &nbsp;
            <button onClick={increase}>+</button>
        </fieldset>
    )
}

export default UseReducerCom